<?php

class CommentTree extends CWidget
{

    public $comments;
    public $level;

    public function init()
    {
	if (!$this->comments) {
	    return false;
	}
    }

    public function run()
    {
	$display = '';
	foreach ($this->comments as $comment) {
	    $display .= $this->render('comment', array('model' => $comment), true);
	    $children = $comment->getChildren();
	    if (!empty($children)) {
		$display .= $this->widget('application.widgets.CommentTree', array('comments' => $children, 'level' => $this->level + 1), true);
	    }
	    $display .= '</div></div>';
	}
	echo $display;
    }

}

?>
